from pymilvus import connections

from app.config.log_config import envLogger as logger
from app.config.milvus import MilvusConfig


def connect_milvus(connection_args: MilvusConfig = MilvusConfig(), alias: str = 'default'):
    """ 连接 milvus 数据库 """
    try:
        connections.connect(
            alias=alias,
            host=connection_args["host"],
            port=connection_args["port"],
            user=connection_args["user"],
            password=connection_args["password"],
            
        )
    except Exception as e:
        logger.error("连接 Milvus 数据库异常")
        raise e
